import threading, queue

q0 = queue.Queue()
q1 = queue.Queue(3)


def produce():
    for item in ["a", "b", "c", "d", "e", "f", "g", "h"]:
        q0.put(item)
        print("produce %s" % item)
        q0.join()


def compute():
    for i in range(8):
        item = q0.get()
        item = item.upper()
        while q1.full():
            pass
        q1.put(item)
        q1.join()


def consume():
    for i in range(8):
        while q1.empty():
            pass
        item = q1.get()
        print(" consume %s" % item)
        q1.task_done()
        q0.task_done()


producer = threading.Thread(target=produce, args=())
computer = threading.Thread(target=compute, args=())
consumer = threading.Thread(target=consume, args=())
producer.start()
computer.start()
consumer.start()
